feat:contrib/model-prism: pluggable LLM backend SPI for ADK Java via ServiceLoader#1199
Open
svetanis wants to merge 1 commit into
Open
feat:contrib/model-prism: pluggable LLM backend SPI for ADK Java via ServiceLoader#1199svetanis wants to merge 1 commit into
ServiceLoader#1199svetanis wants to merge 1 commit into
Conversation
ServiceLoader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
model-prism: pluggable LLM backend SPI for ADK Java viaServiceLoaderPlease ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Related discussion:
2. Description of change:
Problem:
Not every developer has access to a premium model subscription — but every
developer deserves the ability to build robust, production-grade agent systems
that scale. ADK Java already provides a strong foundation with Gemini and the
contrib/langchain4jbridge. This PR extends that foundation with aconvention-based, zero-wiring path for any OpenAI-compatible provider.
Today, using alternative providers like Groq, Ollama, or OpenRouter requires
explicit registration at startup. This PR makes that optional — providers
self-register via
META-INF/services, so adding one is just a Mavendependency.
Why mix models? Use Gemini only where its built-in tools (
GoogleSearchTool,code execution) are genuinely needed. Route heavy generation to fast free-tier
models like Groq or OpenRouter. Run lightweight steps — classification, critique,
formatting — on local Ollama at zero cost. The result is a more capable system
at a fraction of the cost of running every agent on a premium model. Individual
developers and open-source projects can build production-grade multi-agent
pipelines with no enterprise AI subscription required.
Solution:
Introduce a
ServiceLoaderSPI pattern (ModelProviderinterface +ModelProviderRegistry) as acontribmodule. Provider JARs self-register viaMETA-INF/services— adding or removing a provider is a single Maven dependency change with zero application code modifications. A single call toModelProviderRegistry.registerAll()inRunnerorAdkWebServer.start()enables automatic discovery for all ADK applications.This PR introduces a
ServiceLoader-based SPI as acontribmodule.Adding a provider is a single Maven dependency — no application code changes.
Then just use the model by name:
What's included
model-prism-coreModelProviderSPI +OpenAiCompatibleLlmbase classmodel-prism-groqgroq/.*)model-prism-ollamamodel-prism-openroutermodel-prism-demoTests
13 unit tests, all passing. See PR description for full list.
Manual E2E verified with Groq and Ollama.
Proposed core integration (one line)
Testing Plan
Unit Tests:
Manual End-to-End (E2E) Tests:
The
model-prism-demomodule includes 11 runnable demo classes. To verify end-to-end:For Ollama (no API key required): install Ollama, run
ollama pull llama3, then use model nameollama/llama3.Checklist
Additional context
Modules added under
contrib/model-prism/:model-prism-coreModelProviderSPI,ModelProviderRegistry,OpenAiCompatibleLlmbase classmodel-prism-groqgroq/.*)model-prism-ollamaollama/.*, no API key)model-prism-openrouteropenrouter/.*, free tier available)model-prism-demoProposed ADK integration
adk-model-prism-corewould go intogoogle-adk.jarModelProvider.java- public SPI interfaceModelProviderRegistry.java- ServiceLoader wiringOpenAiCompatibleLlm.java- reusable base class for Open-AI-format APIsRunnerandAdkWebServer.start()Provider JARs are published independently - no PRs to ADK core needed for new providers.